import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store/index'
import Cookies from 'js-cookie'
import Home from '@/view/home'
/*
  import Register from '@/view/register'
  import Binding from '@/view/binding'
  import Login from '@/view/login'
  import LosePasswd from '@/view/losePasswd'
*/

import AppointmentAdd from '@/view/appointmentAdd'
import Coupon from '@/view/coupon'
import Appointments from '@/view/appointments'
import AppointmentPay from '@/view/appointmentPay'
import Address from '@/view/address'
import MemberDiscount from '@/view/memberDiscount'
import CommonReservationUsers from '@/view/commonReservationUsers'
import Subscriber from '@/view/subscriber'
import AddCommonUser from '@/view/addCommonUser'

import AppointmentDetail from '@/view/appointmentDetail'
import ProductList from '@/view/productList'
import MyCollecttion from '@/view/myCollecttion'
import HospitalIntroduction from '@/view/hospitalIntroduction'
import News from '@/view/news'
import ProductDetail from '@/view/productDetail'
import HongkongHospital from '@/view/hongkongHospital'
import CaseManagement from '@/view/caseManagement'
import HospitalDepartments from '@/view/hospitalDepartments'
import HospitalDetails from '@/view/hospitalDetails'
import Information from '@/view/information'
import MyRecruitment from '@/view/myRecruitment'
import EditAddress from '@/view/editAddress'

import Myaccount from '@/view/myaccount'

import Vip from '@/view/vip'
import Contactus from '@/view/contactus'
import AddComment from '@/view/addComment'
import Rule from '@/view/rule'
import Integral from '@/view/integral'
import CaseUpload from '@/view/caseUpload'
import WithdrawalsAccount from '@/view/withdrawalsAccount'
import Withdraw from '@/view/withdraw'
import MyComment from '@/view/myComment'
import Vip2 from '@/view/vip2'


// 授权

import Register from '@/view/auth/register'
import Bind from '@/view/auth/bind'
import Login from '@/view/auth/login'
import Oauth from '@/view/auth/oauth'
import OauthWechat from '@/view/auth/oauthWechat'
import LosePasswd from '@/view/auth/losePasswd'

import Self from '@/view/用户/self'
import Member from '@/view/用户/member/vip'
import 收藏 from '@/view/用户/收藏'

import 香港体检 from '@/view/产品/香港体检'
import 香港美容 from '@/view/产品/香港美容'
import 香港疫苗 from '@/view/产品/香港疫苗'

import 香港医院 from '@/view/其他/香港医院'
import Aboutus from '@/view/其他/aboutus'

import 港医咨询 from '@/view/其他/港医咨询'
import 港医咨询详情 from '@/view/其他/港医咨询详情'
import Setting from '@/view/其他/setting'
import aboutus from '@/view/其他/aboutus'
import 人工核保 from '@/view/其他/人工核保'
import 人工核保详情 from '@/view/其他/人工核保详情'




import 专科列表 from '@/view/产品/专科列表'
import 产品详情 from '@/view/产品/产品详情'
import 预约下单 from '@/view/产品/预约下单'
import 预约下单就诊地址 from '@/view/产品/预约下单-就诊地址'
import 预约下单选择就诊人 from '@/view/产品/预约下单-选择就诊人'

import AddUserInfo from '@/view/用户/AddUserInfo'
import Account from '@/view/用户/Account'
import 积分 from '@/view/用户/积分'
import 招募 from '@/view/用户/招募'
import team from '@/view/用户/team'
import 写评价 from '@/view/用户/写评价'
import 会员规则 from '@/view/用户/member/rule'

import Success from '@/view/pay/success'

import 首页 from '@/view/首页/首页'
import 消息 from '@/view/其他/消息'
import 订单 from '@/view/其他/订单'
import 订单详情 from '@/view/其他/订单详情'

import HomeClass from '@/components/HomeClass'

import Mainland from '@/view/pay/mainland'
import MainlandAgency from '@/view/pay/mainlandAgency'
import Allin from '@/view/pay/allin'
import AllinAgency from '@/view/pay/allinAgency'

const $state = store.state

Vue.use(Router)

// 配置路由守卫

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/about/us',
      name: '关于我们',
      component: aboutus,
      meta: {
        title: '关于我们',
        // keepAlive: true 
      }
    },
    {
      path: '/user/member/rule',
      name: '会员规则',
      component: 会员规则,
      meta: {
        title: '会员规则',
        // keepAlive: true aboutus
      }
    },
    {
      path: '/consultdoctor',
      name: '港医咨询',
      component: 港医咨询,
      meta: {
        title: '港医咨询',
        // keepAlive: true 核保 rule
      }
    },
    {
      path: '/consultdoctor/message',
      name: '港医咨询详情',
      component: 港医咨询详情,
      meta: {
        title: '港医咨询详情',
        // keepAlive: true 核保 rule
      }
    },
    {
      path: '/user/point',
      name: '积分',
      component: 积分,
      meta: {
        title: '积分',
        // keepAlive: true 核保 rule
      }
    },
    {
      path: '/underwriter',
      name: '人工核保',
      component: 人工核保,
      meta: {
        title: '人工核保',
        // keepAlive: true 核保
      }
    },
    {
      path: '/underwriter/message',
      name: '人工核保详情',
      component: 人工核保详情,
      meta: {
        title: '人工核保详情',
        // keepAlive: true 
      }
    },
    {
      path: '/user/comment/add',
      name: '写评价',
      component: 写评价,
      meta: {
        title: '写评价',
        // keepAlive: true 评价
      }
    },
    {
      path: '/user/team',
      name: '我的招募',
      component: team,
      meta: {
        title: '我的招募',
        // keepAlive: true team
      }
    },
    {
      path: '/user/recruitment',
      name: '招募会员',
      component: 招募,
      meta: {
        title: '招募会员',
        // keepAlive: true Account 招募 
      }
    },
    {
      path: '/user/add/info',
      name: '用户表单',
      component: AddUserInfo,
      meta: {
        title: '用户表单',
        // keepAlive: true Account 积分
      }
    },
    {
      path: '/user/account',
      name: '我的账户',
      component: Account,
      meta: {
        title: '我的账户',
        // keepAlive: true Account
      }
    },
    {
      path: '/product/order/select/user',
      name: '预约下单-选择就诊人',
      component: 预约下单选择就诊人,
      meta: {
        title: '预约下单-选择就诊人',
        // keepAlive: true 专科列表 预约下单就诊地址 AddUserInfo 预约下单-选择就诊人.vue
      }
    },
    {
      path: '/product/order',
      name: '预约下单',
      component: 预约下单,
      meta: {
        title: '预约下单',
        // keepAlive: true 专科列表 预约下单就诊地址 AddUserInfo
      }
    },
    {
      path: '/product/order/address',
      name: '就诊地址',
      component: 预约下单就诊地址,
      meta: {
        title: '就诊地址',
        // keepAlive: true 专科列表 预约下单就诊地址
      }
    },
    {
      path: '/pay/mainland',
      name: '支付',
      component: Mainland,
      meta: {
        title: '支付',
        // keepAlive: true 专科列表
      }
    },
    {
      path: '/pay/mainlandagency',
      title: '代付',
      name: '代付',
      component: MainlandAgency,
      meta: {
        title: '代付',
        // keepAlive: true 专科列表
      }
    },
    {
      path: '/pay/allin',
      name: '支付',
      component: Allin,
      meta: {
        title: '支付',
        // keepAlive: true 专科列表
      }
    },
    {
      path: '/pay/allinagency',
      name: '代付',
      component: AllinAgency,
      meta: {
        title: '代付',
        // keepAlive: true 专科列表
      }
    },
    //香港医院
    {
      path: '/hongkong/hospital',
      name: '香港医院',
      component: 香港医院,
      meta: {
        title: '香港医院',
        // keepAlive: true 专科列表
      }
    },
    {
      path: '/hongkong/hospital/specialty',
      name: '专科列表',
      component: 专科列表,
      meta: {
        title: '专科列表',
        // keepAlive: true 专科列表 产品详情
      }
    },
    {
      path: '/hongkong/product/detail',
      name: '产品详情',
      component: 产品详情,
      meta: {
        title: '产品详情',
        // keepAlive: true 专科列表 产品详情
      }
    },
    {
      path: '/hongkong/examination',
      name: '香港体检',
      component: 香港体检,
      meta: {
        title: '香港体检',
        // keepAlive: true
      }
    },
    {
      path: '/hongkong/medicalbeauty',
      name: '香港美容',
      component: 香港美容,
      meta: {
        title: '香港美容',
        // keepAlive: true
      }
    },
    {
      path: '/hongkong/vaccine',
      name: '香港疫苗',
      component: 香港疫苗,
      meta: {
        title: '香港疫苗',
        // keepAlive: true
      }
    },
    {
      path: '/',
      name: '首页',
      component: 首页,
      meta: {
        title: '首页',
        // keepAlive: true 消息
      }
    },
    {
      path: '/messages',
      name: '消息',
      component: 消息,
      meta: {
        title: '消息',
        // keepAlive: true 消息 订单
      }
    },
    {
      path: '/order',
      name: '订单',
      component: 订单,
      meta: {
        title: '订单',
        // keepAlive: true 消息 订单 订单详情
      }
    },
    {
      path: '/order/detail',
      name: '订单详情',
      component: 订单详情,
      meta: {
        title: '订单详情',
        // keepAlive: true 消息 订单 订单详情
      }
    },
    {
      path: '/oauth',
      name: 'oauth',
      component: Oauth
    },
    {
      path: '/oauth/wechat',
      name: 'oauthwechat',
      component: OauthWechat
    },
    {
      path: '/auth/register',
      name: 'Register',
      component: Register,
      meta: {
        title: '注册',
      }
    },
    {
      path: '/auth/bind',
      name: 'Bind',
      component: Bind,
      meta: {
        title: '绑定手机',
      }
    },
    {
      path: '/auth/login',
      name: 'Login',
      component: Login,
      meta: {
        title: '登录',
      }
    },
    {
      path: '/auth/resetpasswd',
      name: 'LosePasswd',
      component: LosePasswd,
      meta: {
        title: '忘记密码',
      }
    },
    {
      path: '/user/self',
      name: 'Self',
      component: Self,
      meta: {
        title: '个人中心',
      }
    },
    {
      path: '/user/member',
      name: 'member',
      component: Member,
      meta: {
        title: '会员中心',
      }
    },
    {
      path: '/user/collection',
      name: '收藏',
      component: 收藏,
      meta: {
        title: '收藏',
      }
    }, // 首页分类
    {
      path: '/HomeClass',
      name: 'HomeClass',
      component: HomeClass,
      meta: {
        title: 'HomeClass',
      }
    }, // 首页分类
    {
      path: '/coupon',
      name: 'Coupon',
      component: Coupon,
      meta: {
        title: '优惠券',
      }
    },
    {
      path: '/appointmentAdd',
      name: 'AppointmentAdd',
      component: AppointmentAdd,
      meta: {
        title: '预约',
      }
    },
    {
      path: '/appointments',
      name: 'Appointments',
      component: Appointments,
      meta: {
        title: '我的预约',
      }
    },
    {
      path: '/appointmentPay',
      name: 'AppointmentPay',
      component: AppointmentPay,
      meta: {
        title: '支付',
      }
    }, {
      path: '/address',
      name: 'Address',
      component: Address,
      meta: {
        title: '就诊地址',
      }
    }, {
      path: '/memberDiscount',
      name: 'MemberDiscount',
      component: MemberDiscount,
      meta: {
        title: '会员折扣',
      }
    }, {
      path: '/commonReservationUsers',
      name: 'CommonReservationUsers',
      component: CommonReservationUsers,
      meta: {
        title: '常用预约用户',
      }
    }, {
      path: '/subscriber',
      name: 'Subscriber',
      component: Subscriber,
      meta: {
        title: '常用预约用户',
      }
    }, {
      path: '/addCommonUser',
      name: 'AddCommonUser',
      component: AddCommonUser,
      meta: {
        title: '添加预约用户',
      }
    }, {
      path: '/pay/success',
      name: '支付成功',
      component: Success,
      meta: {
        title: '支付成功',
      }
    }, {
      path: '/appointmentDetail',
      name: 'AppointmentDetail',
      component: AppointmentDetail,
      meta: {
        title: '预约详情',
      }
    }, {
      path: '/productList',
      name: 'ProductList',
      component: ProductList,
      meta: {
        title: '香港体检',
      }
    }, {
      path: '/myCollecttion',
      name: 'MyCollecttion',
      component: MyCollecttion,
      meta: {
        title: '我的收藏',
      }
    }, {
      path: '/hospitalIntroduction',
      name: 'HospitalIntroduction',
      component: HospitalIntroduction,
      meta: {
        title: '医院介绍',
      }
    }, {
      path: '/news',
      name: 'News',
      component: News,
      meta: {
        title: '消息中心',
      }
    }, {
      path: '/productDetail',
      name: 'ProductDetail',
      component: ProductDetail,
      meta: {
        title: '详情',
      }
    }, {
      path: '/hongkongHospital',
      name: 'HongkongHospital',
      component: HongkongHospital,
      meta: {
        title: '香港医院',
      }
    }, {
      path: '/hospitalDepartments',
      name: 'HospitalDepartments',
      component: HospitalDepartments,
      meta: {
        title: '专科列表',
      }
    }, {
      path: '/caseManagement',
      name: 'CaseManagement',
      component: CaseManagement,
      meta: {
        title: '病例管理',
      }
    }, {
      path: '/information',
      name: 'Information',
      component: Information,
      meta: {
        title: '个人信息',
      }
    }, {
      path: '/hospitalDetails',
      name: 'HospitalDetails',
      component: HospitalDetails,
      meta: {
        title: '医院详情',
      }
    }, {
      path: '/myRecruitment',
      name: 'MyRecruitment',
      component: MyRecruitment,
      meta: {
        title: '我的招募',
      }
    }, {
      path: '/editAddress',
      name: 'EditAddress',
      component: EditAddress,
      meta: {
        title: '修改地址',
      }
    }, {
      path: '/about/us',
      name: '关于我们',
      component: Aboutus,
      meta: {
        title: '关于我们',
      }
    }, {
      path: '/myaccount',
      name: 'MyAccount',
      component: Myaccount,
      meta: {
        title: '我的账户',
      }
    }, {
      path: '/setting',
      name: 'Setting',
      component: Setting,
      meta: {
        title: '设置',
      }
    }, {
      path: '/vip',
      name: 'Vip',
      component: Vip,
      meta: {
        title: '我的会员',
      }
    }, {
      path: '/contactus',
      name: 'Contactus',
      component: Contactus,
      meta: {
        title: '联系我们',
      }
    }, {
      path: '/addComment',
      name: 'AddComment',
      component: AddComment,
      meta: {
        title: '添加评论',
      }
    }, {
      path: '/rule',
      name: 'Rule',
      component: Rule,
      meta: {
        title: '隐私协议',
      }
    }, {
      path: '/integral',
      name: 'Integral',
      component: Integral,
      meta: {
        title: '积分账户',
      }
    }, {
      path: '/caseUpload',
      name: 'CaseUpload',
      component: CaseUpload,
      meta: {
        title: '病例上传',
      }
    }, {
      path: '/withdrawalsAccount',
      name: 'WithdrawalsAccount',
      component: WithdrawalsAccount,
      meta: {
        title: '提现账户',
      }
    }, {
      path: '/withdraw',
      name: 'Withdraw',
      component: Withdraw,
      meta: {
        title: '提现',
      }
    }, {
      path: '/myComment',
      name: 'MyComment',
      component: MyComment,
      meta: {
        title: '我的评论',
      }
    }, {
      path: '/vip2',
      name: 'Vip2',
      component: Vip2,
      meta: {
        title: '我的会员',
      }
    }
  ]
})

// //微信title
// router.afterEach(route => {
//   // 从路由的元信息中获取 title 属性
//   if (route.meta.title) {
//     document.title = route.meta.title;
//     // 如果是 iOS 设备，则使用如下 hack 的写法实现页面标题的更新
//     if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
//       const hackIframe = document.createElement('iframe');
//       hackIframe.style.display = 'none';
//       hackIframe.src = '/static/html/fixIosTitle.html?r=' + Math.random();
//       document.body.appendChild(hackIframe);
//       setTimeout(_ => {
//         document.body.removeChild(hackIframe)
//       }, 300)
//     }
//   }
// });
router.beforeEach((to, from, next) => {
  next();
})
router.afterEach((to) => {
  if (window.location.pathname + window.location.search != to.fullPath) { // 微信ISO 的坑
    // window.location.href = to.fullPath
  }
})

export default router;
